
using System;

namespace ICommonLibrary.Date {

    public sealed class YearMonthDaySpan : IComparableDate {

        public int Years {
            get { return _years; }
            set {
                SetYears(value);
            }
        }

        public int Months {
            get { return _months; }
            set {
                SetMonths(value);
            }
        }

        public int Days {
            get { return _days; }
            set {
                SetDays(value);
            }
        }

        
	    private int _years;
	    private int _months;
        private int _days;

        public YearMonthDaySpan(int years, int months, int days) {
		    _years = years;
		    _months = months;
	        _days = days;
	    }

        public YearMonthDaySpan Clone() {
            return new YearMonthDaySpan(_years, _months, _days);
	    }

	    public int GetYears() {
		    return _years;
	    }

	    public void SetYears(int years) {
		    _years = years;
	    }

	    public int GetMonths() {
		    return _months;
	    }

	    public void SetMonths(int months) {
		    _months = months;
	    }
    	
	    public int GetDays() {
	        return _days;
	    }

        public void SetDays(int days) {
            _days = days;
        }

        public bool Before(MutableDate date) {
            MutableDate refDate = Resolve(DateTime.Now);
            return refDate.Before(date);
        }

        public bool After(MutableDate date) {
            MutableDate refDate = Resolve(DateTime.Now);
            return refDate.After(date);
        }

        public MutableDate Resolve(DateTime baseDate) {
            return new MutableDate(
                baseDate.Year  + _years, 
                baseDate.Month + _months - 1, // convert 1-12 to 0-11
                baseDate.Day   + _days
            );
        }
    	
        public override int GetHashCode() {
            return _years * 10000 + _months * 100 + _days;
        }

        public override bool Equals(object o) {
		    if (o == this) {
			    return true;
		    }
            if (o != null && o.GetType() == typeof(YearMonthDaySpan)) {
			    var span = (YearMonthDaySpan) o;
			    return 	_years  == span._years && 
					    _months == span._months &&
                        _days   == span._days;
		    }
		    return false;
	    }
        
    }
}